<template>
<div>
    <mt-header title="访问设置">
        <router-link to="/safty/login" slot="left">
            <i class="fa fa-times fa-2x"></i>
        </router-link>  
        
        
        <mt-button type="primary" @click.native="saveSetting" slot="right"><i class="fa fa-check-square-o fa-2x"></i></mt-button>
         
    </mt-header>

    <mt-field label="服务器IP" v-model="config.ip"></mt-field>
    <mt-field label="服务器端口" v-model="config.port"></mt-field>
    <mt-field label="服务器应用" v-model="config.app"></mt-field>
    

</div>
</template>

<script>
export default {
    name:'SaftySetting',
    data(){
        return {

            config:{
                ip:"localhost",
                port:"80",
                app:""
            }

        };
    },
    methods:{
        saveSetting(){
            
            let ip = this.config.ip && this.config.ip!=''?this.config.ip:'localhost';

            let port = this.config.port && this.config.port!='' 
                                        && !isNaN(parseInt(this.config.port)) 
                                        && this.config.port!='80'? `:${this.config.port}` : ``;

            let app = this.config.app?`/${this.config.app}`:``;

            this.$axios.defaults.baseURL = `http://${ip}${port}${app}`;

            //console.log(this.$axios.defaults.baseURL);

            let toast = this.$toast({
                message: '操作成功',
                iconClass: 'fa fa-check fa-3x', //使用font-awesome的字体图标
                duration:1000 
            });

            setTimeout(()=>{                
                this.$router.push('/safty/login?_t='+new Date().getTime());
            },1200);
        }
    }
}
</script>
<style scoped>
    
</style>


